package telnetserver;

public class Info {
    private Telnet telnet;
    private Object ret;
    
    public Info(Telnet t, Object r) {
        telnet = t;
        ret = r;
    }
    
    public void addUser(User u) {
        u.setCanWrite(false);
        u.setCanPress(false);
        
        u.clear();
        u.prepare(1, 5, 5, "SERVER INFO:");
        
        long time = (System.currentTimeMillis() - telnet.getStartTime()) / 1000;
        
        int days = (int)(time / 86400);
        time -= (days * 86400);
        int hours = (int)(time / 3600);
        time -= (hours * 3600);
        int minutes = (int)(time / 60);
        time -= (minutes * 60);
        
        u.prepare(5, 7, "Server uptime (Days/Hours/Minutes/Seconds):  " + days + ":" + hours + ":" + minutes + ":" + time);
        u.prepare(5, 8, "Users online: " + telnet.getUsersOnline());
        u.prepare(5, 9, "Most users online: " + telnet.getMostUsers());
        
        
        u.prepare(7, 4, 22, "BACK");
        u.prepare(0, 8, 22, "");
        u.send();
    }
    
    public void read(User u, String s) {
        telnet.changeMode(u, ret);
    }
}
